package com.mentaleye.service.impl;

import com.mentaleye.dal.model.TradesRecord;
import com.mentaleye.dal.model.TrxRecord;
import com.mentaleye.dal.model.TrxRecordExample;
import com.mentaleye.dal.service.TradesRecordMapper;
import com.mentaleye.dal.service.TrxRecordMapper;
import com.mentaleye.enumpackage.TradeStatusEnum;
import com.mentaleye.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Skeyedu on 2017/6/15.
 */

@Service
public class OrderServiceImpl implements OrderService {
    @Autowired
    TradesRecordMapper tradesRecordMapper;

    @Autowired
    TrxRecordMapper trxRecordMapper;

    @Override
    public void failTRX(List<String> failTrxRecordNos) {
        TrxRecordExample example=new TrxRecordExample();
        example.createCriteria().andTrxNoIn(failTrxRecordNos
        );
        TrxRecord record=new TrxRecord();
        record.setTrxStatus(TradeStatusEnum.FAILED.name());
        trxRecordMapper.updateByExampleSelective(record ,example);

    }

    @Override
    public List<TrxRecord> getTRXByOrderNo(String orderNo,String trxType,String trxStatus) {
        TrxRecordExample example=new TrxRecordExample();
        example.createCriteria().andTrxOrderNoEqualTo(orderNo).andTrxTypeEqualTo(
                trxType).andTrxStatusEqualTo(trxStatus);
        return trxRecordMapper.selectByExample(example);
    }

    @Override
    public void updateTrxRecord(TrxRecord trxRecord) {
        trxRecordMapper.updateByPrimaryKeySelective(trxRecord);
    }

    @Override
    public void insertTrxRecord(TrxRecord trxRecord) {
        trxRecordMapper.insertSelective(trxRecord);
    }

    @Override
    public TrxRecord getByTrxNo(String trxNo) {
        return trxRecordMapper.selectByPrimaryKey(trxNo);
    }

    @Override
    public void updateOrder(TradesRecord order) {
        tradesRecordMapper.updateByPrimaryKeySelective(order);
    }

    @Override
    public TradesRecord getByOrderNo(String orderNo) {
        return  tradesRecordMapper.selectByPrimaryKey(
                orderNo
        );
    }

    @Override
    public TradesRecord getByTransNo(String trxNo) {
        return tradesRecordMapper.selectByTrxNo(trxNo);
    }
}
